$(function () {
	//已跳过课程作业
	//save line：529
	//和SMcoursebasicinfo line：634
	$("#createCourse>ul.nav>li[role='presentation']:nth-child(3)").removeClass("disabled").addClass("disabled");
	//修改课程
	if (typeof (LessonID) == "number") {
		setCoursebasicinfo("#ctcourse");
	} else {
		//设置课程类型、标签
		getsetLessonType();
		$("#createCourse>ul.nav>li[role='presentation']:nth-child(n+2)").removeClass("disabled").addClass("disabled");
	}
	//UI控制
	var setUI = function () {
		$("#ctcourse div.centerBtn img").each(function (index, e) {
			$(e).height(e.getAttribute("id") == "courseAvatar" ? $(e).width() / 1.8 : $(e).width());
		});
		$("#teacherIntro").height($("#teacherAvatar").height() - 30);
		$("#modelUserimg").height($("#modelUserimg").width());
	};
	//鼠标提示
	$("div.greyBG img[data-act='add']").attr("title", langThis("cs_addAssistantTea"));
	window.onresize = setUI;
	//闭包缓存默认头像
	(function (getsetdefaultavatar) {
		setTimeout(function () {
			setUI();
		}, 120);
		var imgs = [];
		if (!imgs.length) {
			$.ajax({
				url: "photos",
				type: "GET",
				contentType: "application/json",
				success: function (e) {
					if (e && e.rows) {
						for (var i in e.rows) {
							var img = new Image();
							img.setAttribute("class", "userAva");
							//img.setAttribute("src","./photos/" + e.rows[i].id);
							img.setAttribute("src", e.rows[i].url);
							img.setAttribute("serverimgID", e.rows[i].id);
							imgs.push(img);
						}
						getsetdefaultavatar(imgs);
					}
				},
				error: function (event) {
					// console.log(data);
				}
			});
		}
	})(getsetdefaultavatar);
});
//获取设置课程类型、标签
function getsetLessonType(tp, tg) {
	var lang = getCurrentLang() == "en" ? "ename" : "name";
	//课程类型
	$.ajax({
		url: "lessontype",
		type: "GET",
		contentType: "application/json",
		success: function (data) {
			var opts = "";
			for (var i in data.rows) {
				opts += '<option value="' + data.rows[i].id + '" ' + (data.rows[i].id == tp ? "selected" : "") + '>' + data.rows[i][lang] + '</option>';
			}
			$("select.LSType").html(opts);
		},
		error: function (event) {
			// console.log(event);
		}
	});
	// 课程标签
	$.ajax({
		url: "tag",
		type: "GET",
		contentType: "application/json",
		success: function (data) {
			var tags = "";
			for (var i in data.rows) {
				var choosed = "btn btn-default";
				if (tg) {
					for (var t in tg) {
						if (tg[t] == data.rows[i].id) {
							choosed = "btn btn-info";
						}
					}
				}
				tags += '<button type="button" tagid="' + data.rows[i].id + '" class="' + choosed + '">' + data.rows[i][lang] + ' <span class="badge"><span class="glyphicon glyphicon-ok"></span></span></button>';
			}
			$("#SVTags").html(tags);
			$("#SVTags>button").click(function () {
				if (this.getAttribute("class") == "btn btn-default") {
					this.setAttribute("class", "btn btn-info");
				} else {
					this.setAttribute("class", "btn btn-default");
				}
			});
		},
		error: function (event) {
			// console.log(event);
		}
	});
}
//设置高度
function setcourseexciseIframeheight(ht) {
	$("#setcourseexciseIframe").height(ht);
}
function sethomeworkIframeheight(ht) {
	$("#sethomeworkIframe").height(ht);
}
// 默认头像
function getsetdefaultavatar(s) {
	getsetdefaultavatar.toggle = function (e) {
		if (e) {
			getsetdefaultavatar(s);
		} else {
			$("#modelUserimg").unbind();
		}
	};
	var avatips;
	// hover选择默认头像
	$("#modelUserimg").unbind().mouseenter(function (e) {
		avatips = layer.tips("<div class='AvatarCan'></div>", '#modelUserimg', {
			tips: [2, '#eee'], //右边
			time: 180000
		});
		$(".layui-layer-content>div.AvatarCan").append(s);
		$(".layui-layer-content>div.AvatarCan").css({
			"max-width": "300px",
			"max-height": $("#modelUserimg").height() + 60,
			"overflow": "auto"
		});

		$(".layui-layer.layui-layer-tips").mouseleave(function () {
			layer.close(avatips);
		});
		$(".layui-layer.layui-layer-tips img.userAva").click(function (e) {
			$("#modelUserimg").attr("src", e.target.getAttribute("src"));
			$("#modelUserimg").attr("serverimgID", e.target.getAttribute("serverimgID"));
			$('#changeUserImgNm').html(langThis("mi_avatarupload"));
			$("#changeUserImg").val("");
			layer.close(avatips);
		});
	});
	$("body").click(function () {
		layer.close(avatips);
	});
}
// 读上传的图片
function redUserAvatar(did) {
	var file = document.getElementById(did).files[0];
	// 检查文件是否选择:
	if (!file) {
		if (did == "selectAvatar") {
			if (SMcoursebasicinfo.Lessonxxk && SMcoursebasicinfo.Lessonxxk.image != "./imgs/lessonDefault.png") {
				$("#courseAvatar").attr("src", SMcoursebasicinfo.Lessonxxk.image).css("width", "50%").height($("#courseAvatar").width() / 1.8);
			} else {
				$("#courseAvatar").attr("src", "./imgs/lessonDefault.png").css("width", "30%").height($("#courseAvatar").width() / 1.8);
			}
			$('#selectAvatarNm').html(langThis("cm_coverupload"));
		} else {
			$("#modelUserimg").attr("src", UserInfo.photo);
			$("#modelUserimg").attr("serverimgid", null);
			$('#changeUserImgNm').html(langThis("mi_avatarupload"));

			var sltUFDiv = $("#sltUavaFile");
			sltUFDiv.css("margin-top", sltUFDiv.parent().width() - sltUFDiv.width() < 15 ? "32px" : "10px");
		}
		return;
	}
	// 读取文件:
	var reader = new FileReader();
	reader.onload = function (e) {
		//检查过滤图片格式
		var imgform = file.name.slice(file.name.lastIndexOf(".") + 1);
		switch (imgform.toLowerCase()) {
			case "jpg": break;
			case "jpeg": break;
			case "png": break;
			case "bmp": break;
			case "gif": break;
			default: {
				layer.msg(langThis("mi_wrongImgForm"), { icon: 2 });
				$("#usrImgFile").val("");
				return;
			}
		}
		var filename = file.name.slice(0, file.name.lastIndexOf("."))
		//显示图片
		var data = e.target.result;
		if (did == "selectAvatar") {
			$("#courseAvatar").attr("src", data);
			$("#courseAvatar").css("width", "50%");
			$("#courseAvatar").height($("#courseAvatar").width() / 1.8);
			$('#selectAvatarNm').html('<span class="badge">' + imgform + '</span> ' + filename);
		} else {
			$("#modelUserimg").attr("src", data);
			$("#modelUserimg").attr("serverimgid", null);
			$('#changeUserImgNm').html('<span class="badge">' + imgform + '</span> ' + filename);
			var sltUFDiv = $("#sltUavaFile");
			sltUFDiv.css("margin-top", sltUFDiv.parent().width() - sltUFDiv.width() < 15 ? "32px" : "10px");
		}
	};
	// 以DataURL的形式读取文件:
	reader.readAsDataURL(file);
}
//添加教师、显示教师信息模态框
$('#addteacher').on('show.bs.modal', function (e) {
	var uif = {
		Uid: e.relatedTarget.getAttribute("data-act"),
		logname: e.relatedTarget.getAttribute("LOGNAME"),
		nickname: e.relatedTarget.getAttribute("NICKNM")
	};
	delete checkAstInfo.UInfo;
	// 图片高宽
	$("#modelUserimg").height($("#modelUserimg").width());
	$("#modelUserimg").attr("serverimgid", "");
	//默认头像显示
	getsetdefaultavatar.toggle(false);
	//上传教师头像
	var uploaduserImg = function () {
		// 默认头像
		var defaultimg = parseInt($("#modelUserimg").attr("serverimgid"));
		if (defaultimg) {
			$("#teacherAvatar").attr("src", $("#modelUserimg").attr("src"));
			$("#teacherAvatar").height($("#teacherAvatar").width());
			$('#addteacher').modal('hide');
			return;
		} else if (!$("#changeUserImg").val()) {
			$('#addteacher').modal('hide');
			return;
		}
		var loading = layer.load(2, {
			shade: [0.5, "#eee"]
		});
		$.ajaxFileUpload({
			url: "photos",
			secureuri: false,
			type: "POST",
			fileElementId: ["changeUserImg"],
			dataType: "json",
			success: function (data) {
				UserInfo.photo = data.url;
				layer.close(loading);
				layer.msg(langThis("myinfo_changeSuceess"), { icon: 1 });
				$("#teacherAvatar").attr("src", UserInfo.photo);
				$('#addteacher').modal('hide');
			},
			error: function (event) {
				layer.close(loading);
				layer.msg(langThis("role_optionfaild"), { icon: 2 });
			}
		});
	};
	//添加助教检查逻辑
	var checkASTC = function (fun) {
		if (checkAstInfo.UInfo) {
			//不能添加自己和重复添加
			if (checkAstInfo.UInfo.id == UserID) {
				layer.msg(langThis("ms_repeatSelf"), { icon: 7 });
			} else {
				var checkrepeat = true;
				$("#ASTList button.mbadge").each(function () {
					if (this.getAttribute("Uid") = checkAstInfo.UInfo.id) {
						checkrepeat = false;
					}
				});
				if (checkrepeat) {
					fun();
					$('#addteacher').modal('hide');
				} else {
					layer.msg(langThis("ms_repeatASTC"), { icon: 7 });
				}
			}
		} else {
			$('#addteacher').modal('hide');
		}
	};
	switch (uif.Uid) {
		case "add": {
			$("#addteachertitle").html(langThis("cs_addAssistantTea"));
			$("#addteacher div.searchUser,div.modal-footer>button[data-dismiss]").show();
			$("#UserInfoCan,#sltUavaFile").hide();

			$("#addOrModifyTeaBtn").unbind("click").click(function () {
				checkASTC(function () {
					addMdfAssTea(checkAstInfo.UInfo);
				});
			});
		} break;
		case UserID: {
			$("#addteachertitle").html(langThis("cs_chkAssistantTea"));
			$("#addteacher div.searchUser,div.modal-footer>button[data-dismiss]").hide();
			$("#UserInfoCan,#sltUavaFile").show();
			//清选择文件的显示
			$('#changeUserImgNm').html(langThis("mi_avatarupload"));
			$("#changeUserImg").val("");
			var sltUFDiv = $("#sltUavaFile");
			sltUFDiv.css("margin-top", sltUFDiv.parent().width() - sltUFDiv.width() < 15 ? "32px" : "10px");

			//填充
			UserInfo.photo = $("#teacherAvatar").attr("src");
			fillAoMmodel(UserInfo);
			getsetdefaultavatar.toggle(true);
			$("#addOrModifyTeaBtn").unbind("click").click(function () {
				// 上传头像
				uploaduserImg();
			});
		} break;
		default:
			{
				$("#addteachertitle").html(langThis("cs_mdfAssistantTea"));
				$("#addteacher div.searchUser,div.modal-footer>button[data-dismiss]").show();
				$("#sltUavaFile").hide();
				$("#AST_name").val(uif.logname);
				$("#AST_nickname").val(uif.nickname);
				checkAstInfo();

				$("#addOrModifyTeaBtn").unbind("click").click(function () {
					checkASTC(function () {
						var assT = e.relatedTarget;
						assT.src = checkAstInfo.UInfo.photo;
						assT.title = checkAstInfo.UInfo.name;
						assT.setAttribute("data-act", checkAstInfo.UInfo.id);
						assT.setAttribute("LOGNAME", checkAstInfo.UInfo.username);
						assT.setAttribute("NICKNM", checkAstInfo.UInfo.nickname);
					});
				});
			}
	}
});
//验证助教信息
function checkAstInfo() {
	var name = $("#AST_name").val(), nickname = $("#AST_nickname").val();
	if (name && nickname) {
		var ASTInfo = {
			username: name,
			nickname: nickname
		};
		var loading = layer.load(2, {
			shade: [0.5, "#eee"]
		});
		$.ajax({
			url: "userinfos/checklessonassistant",
			type: "POST",
			contentType: "application/json",
			data: JSON.stringify(ASTInfo),
			dataType: "json",
			success: function (data) {
				var UInfo = {
					photo: "photos/" + data.photo,
					name: data.name,
					university: data.university,
					nickname: data.nickname,
					major: data.major,
					sex: data.sex,
					enteryear: data.enteryear,
					id: data.id,
					username: data.username
				};
				fillAoMmodel(UInfo);
				checkAstInfo.UInfo = UInfo;
				layer.close(loading);
			},
			error: function (event) {
				layer.close(loading);
				$("#UserInfoCan").hide();
				layer.msg(langThis("kc_nomatches"), { icon: 2 });
			}
		});
	} else {
		return;
	}
}
//移除助教
function removeAssTea(e) {
	$(e).parent("div.col-xs-2").remove();
}
function addMdfAssTea(UInfo) {
	var newTea = '<div class="col-xs-2">';
	newTea += '<img LOGNAME="' + UInfo.username + '" NICKNM="' + UInfo.nickname + '" title="' + UInfo.name + '" src="' + UInfo.photo + '" data-act="' + UInfo.id + '" data-toggle="modal" data-target="#addteacher" alt="Userimg">';
	newTea += '<button Uid="' + UInfo.id + '" title="' + langThis("pm_delete") + '" onclick="removeAssTea(this)" class="btn btn-danger mbadge"><span class="glyphicon glyphicon-minus"></span></button>';
	$("#ASTList div.addTea").before(newTea);
	$("#ASTList img").height($("#ASTList img").width());
}
//填充模态框用户详情
function fillAoMmodel(uif) {
	$("#addteacher img[alt='Userimg']").attr("src", uif.photo);
	var tString = '<tr><td><span>' + langThis("pm_studentName") + ' : <label>' + uif.name + '</label></span></td>';
	tString += '<td><span>' + langThis("pm_school") + ' : <label>' + uif.university + '</label></span></td></tr>';
	tString += '<tr><td><span>' + langThis("ms_nickname") + ' : <label>' + uif.nickname + '</label></span></td>';
	tString += '<td><span>' + langThis("ms_major") + ' : <label>' + uif.major + '</label></span></td></tr>';
	var Sex = parseInt(uif.sex);
	switch (Sex) {
		case 1: Sex = langThis("ms_male"); break;
		case 2: Sex = langThis("ms_female"); break;
		case 3: Sex = langThis("ms_malefemale"); break;
	}
	tString += '<tr><td><span>' + langThis("ms_sex") + ' : <label>' + Sex + '</label></span></td>';
	tString += '<td><span>' + langThis("pm_classDes") + ' : <label>' + uif.enteryear + '</label></span></td></tr>';
	$("#userInfobody").html(tString);
	$("#UserInfoCan").show();
}
//绑定步骤标签点事件
$('#createCourse>ul>li>a[data-toggle="tab"]').click(function (e) {
	if ($(e.currentTarget).parent('li[role="presentation"]').attr("class")) {
		e.preventDefault();
		e.stopImmediatePropagation();
		return;
	}
	$('#container>img[alt="loading"]').show();
	hideSavebtn();
	var divid = e.target.getAttribute("href");
	if (typeof (LessonID) == "number") {
		switch (divid) {
			//课程基本信息
			case "#ctcourse": {
				if (!setCoursebasicinfo.rp) {
					setCoursebasicinfo(divid);
				} else {
					$('#container>img[alt="loading"]').hide();
				}
			} break;
			//创建实验
			case "#setcourseexcise": setcoursetestinfo(); break;
			//设置作业
			case "#sethomework": setcourseworkinfo(); break;
			//发布课程
			case "#publishcourse": setcoursepubtinfo(divid); break;
		}
	} else {
		$('#container>img[alt="loading"]').hide();
	}
});
//填充基本信息
function setCoursebasicinfo(divid) {
	setTimeout(function () {
		$("#courseAvatar").css("width", "50%").height($("#courseAvatar").width() / 1.8);
	}, 180);
	var fill = function (data) {
		var basicArgus = {
			name: data.lessonname,
			description: data.description,
			ownerdes: data.ownerdes,
			owner: UserID,
			ownerphoto: data.ownerphoto,
			typeid: data.typeid,
			image: data.image,
			id: LessonID
		};
		basicArgus.assistantids = [];
		basicArgus.tagids = (function () {
			var ids = [];
			for (var j in data.tags) {
				ids.push(parseInt(data.tags[j].id));
			}
			return ids;
		})();
		$("#courseNameString").val(basicArgus.name);
		$("#courseAvatar").attr("src", basicArgus.image);
		$("#courseIntro").text(basicArgus.description);
		$("#teacherIntro").text(basicArgus.ownerdes);
		$("#teacherAvatar").attr("src", basicArgus.ownerphoto);
		$("#ctcourse div.addTea").prevAll().remove();
		for (var i in data.lessonassistant) {
			data.lessonassistant[i].photo = "photos/" + data.lessonassistant[i].photo;
			addMdfAssTea(data.lessonassistant[i]);
			basicArgus.assistantids.push(data.lessonassistant[i].id);
		}
		getsetLessonType(basicArgus.typeid, basicArgus.tagids);
		SMcoursebasicinfo.Lessonxxk = basicArgus;
		$('#container>img[alt="loading"]').fadeOut();
		setCoursebasicinfo.rp = true;
	};
	//服务
	$.ajax({
		url: "lessons/" + LessonID,
		type: "GET",
		contentType: "application/json",
		success: fill,
		error: function (event) {
			setCoursebasicinfo.rp = false;
			layer.msg(langThis("role_optionfaild"));
			$('#container>img[alt="loading"]').fadeOut();
		}
	});
}
//填充实验信息
function setcoursetestinfo() {
	var fill = function () {
		$('#container>img[alt="loading"]').fadeOut();
	};
	var iframe = document.getElementById("setcourseexciseIframe");
	iframe.src = "./LabManager?lid=" + LessonID;
	if (iframe.attachEvent) {
		iframe.attachEvent("onload", fill);
	} else {
		iframe.onload = fill;
	}
}
//填充作业信息
function setcourseworkinfo(divid) {
	var fill = function () {
		$('#container>img[alt="loading"]').fadeOut();
	};
	var iframe = document.getElementById("sethomeworkIframe");
	iframe.src = "./homewoker?lid=" + LessonID;
	if (iframe.attachEvent) {
		iframe.attachEvent("onload", fill);
	} else {
		iframe.onload = fill;
	}
}
//填充发布信息
function setcoursepubtinfo(divid) {
	$("#PUB_LessonCover").attr("src", SMcoursebasicinfo.Lessonxxk.image);
	$("#PUB_LessonName").text(SMcoursebasicinfo.Lessonxxk.name);
	$("#PUB_TeacherName").text(UserInfo.name);
	$('#container>img[alt="loading"]').fadeOut();
}
// 修改
function save(num, flag) {
	switch (num) {
		//修改基本信息
		case 1: {
			SMcoursebasicinfo(num, flag);
		} break;
		//修改实验
		case 2: {
			SMcoursetestinfo(num + 1, flag);
		} break;
		//修改作业
		case 3: {
			SMcourseworkinfo(num, flag);
		} break;
		//发布课程
		case 4: {
			coursepublish();
		} break;
	}
}
//下一步
function gotonextstep(num, flag) {
	if (typeof (flag) == "boolean") {
		$('#createCourse>ul>li:nth-child(' + (num + 1) + ')>a[role="tab"]').click();
	} else {
		$('#container>img[alt="loading"]').fadeOut();
	}
}
//保存、修改基本信息
function SMcoursebasicinfo(num, flag) {
	var Lessonxxk = {};
	Lessonxxk.name = $("#courseNameString").val();
	Lessonxxk.description = $("#courseIntro").val();
	Lessonxxk.ownerdes = $("#teacherIntro").val();
	var emptTip = function (divid) {
		$(divid).css("box-shadow", "0 0 5px red");
		setTimeout(function () { $(divid).css("box-shadow", ""); }, 200);
		setTimeout(function () { $(divid).css("box-shadow", "0 0 5px red"); }, 400);
		setTimeout(function () { $(divid).css("box-shadow", ""); }, 2000);
	};
	//验证
	for (var i in Lessonxxk) {
		if (!Lessonxxk[i]) {
			layer.msg(langThis("myinfo_lgNameEmpty"), { icon: 0 });
			switch (i) {
				case "name": emptTip("#courseNameString"); $("#courseNameString").focus(); break;
				case "description": emptTip("#courseIntro"); $("#courseIntro").focus(); break;
				case "ownerdes": emptTip("#teacherIntro"); $("#teacherIntro").focus(); break;
			}
			return;
		}
	}
	Lessonxxk.owner = UserID;
	Lessonxxk.ownerphoto = $("#teacherAvatar").attr("src");
	Lessonxxk.typeid = parseInt($("select.LSType").val());
	Lessonxxk.assistantids = (function () {
		var astids = [];
		$("#ASTList button.mbadge").each(function () {
			astids.push(this.getAttribute("Uid"));
		});
		return astids;
	})();
	Lessonxxk.tagids = (function () {
		var tids = [];
		$("#SVTags>button.btn-info").each(function () {
			tids.push(parseInt(this.getAttribute("tagid")));
		});
		return tids;
	})();
	Lessonxxk.image = $("#courseAvatar").attr("src");
	Lessonxxk.id = LessonID;
	//无修改不提交
	if (SMcoursebasicinfo.Lessonxxk){
		var hasChangeFlag = false;
		for (var m in Lessonxxk) {
			if (typeof (Lessonxxk[m]) == "object") {
				//null
				if (Lessonxxk[m] == SMcoursebasicinfo.Lessonxxk[m]) {
					continue;
				} else if (Lessonxxk[m] && SMcoursebasicinfo.Lessonxxk[m] && Lessonxxk[m].length == SMcoursebasicinfo.Lessonxxk[m].length) {//对象或数组长度相等
					for (var r in Lessonxxk[m]) {
						if (Lessonxxk[m][r] != SMcoursebasicinfo.Lessonxxk[m][r]) {
							hasChangeFlag = true;
							break;
						}
					}
				} else {
					hasChangeFlag = true;
				}
				if (hasChangeFlag) {
					break;
				}
			} else {
				if (Lessonxxk[m] != SMcoursebasicinfo.Lessonxxk[m]) {
					hasChangeFlag = true;
					break;
				}
			}
		}
		if (!hasChangeFlag) {
			layer.msg(langThis("mi_OprationSucess"), { icon: 1 });
			gotonextstep(num, flag);
			return;
		}
	}
	var loading = layer.load(2, {
		shade: [0.5, "#eee"]
	});
	//创建课程
	var CreateCS = function () {
		delete Lessonxxk.id;
		$.ajax({
			url: "lessons",
			type: "POST",
			contentType: "application/json",
			data: JSON.stringify(Lessonxxk),
			dataType: "json",
			success: function (data) {
				layer.close(loading);
				layer.msg(langThis("kc_lessonaddsucess"), { icon: 1 });
				LessonID = parseInt(data.id);
				LessonID=isNaN(LessonID)?null:LessonID;
				Lessonxxk.id=LessonID;
				$("#createCourse>ul.nav>li[role='presentation']:nth-child(n+2)").removeClass("disabled");
				//暂时没有课程作业
				$("#createCourse>ul.nav>li[role='presentation']:nth-child(3)").removeClass("disabled").addClass("disabled");
				SMcoursebasicinfo.Lessonxxk = Lessonxxk;
				gotonextstep(num, flag);
			},
			error: function (event) {
				layer.close(loading);
				layer.msg(langThis("kc_lessonaddfailed"), { icon: 2 });
			}
		});
	};
	// 修改课程
	var MdfCS = function () {
		$.ajax({
			url: "lessons/" + LessonID,
			type: "PUT",
			contentType: "application/json",
			data: JSON.stringify(Lessonxxk),
			dataType: "json",
			success: function (data) {
				layer.close(loading);
				layer.msg(langThis("myinfo_changeSuceess"), { icon: 1 });
				SMcoursebasicinfo.Lessonxxk = Lessonxxk;
				gotonextstep(num, flag);
			},
			error: function (event) {
				layer.close(loading);
				layer.msg(langThis("role_optionfaild"), { icon: 2 });
			}
		});
	};
	//头像，先用上传封面服务
	if (Lessonxxk.image == "./imgs/lessonDefault.png") {
		layer.close(loading);
		layer.msg(langThis("cs_lessonAvatartip"), { icon: 0 });
		$("#selectAvatar").focus();
	} else if ($("#selectAvatar").val()) {
		//上传课程封面
		$.ajaxFileUpload({
			url: "lessons/uploadlessoncover",
			secureuri: false,
			type: "POST",
			fileElementId: ["selectAvatar"],
			dataType: "json",
			success: function (data) {
				Lessonxxk.image = data;
				$("#courseAvatar").attr("src", data);
				if (typeof (LessonID) !== "number") {
					CreateCS();
				} else {
					MdfCS();
				}
			},
			error: function (event) {
				layer.closeAll();
				layer.msg(langThis("role_optionfaild"), { icon: 2 });
			}
		});
	} else {
		if (typeof (LessonID) !== "number") {
			CreateCS();
		} else {
			MdfCS();
		}
	}
}
//保存、修改实验
function SMcoursetestinfo(num, flag) {
	var divcan = $("#setcourseexcise");
	if (!typeof (LessonID) == "number") {
		// console.log("保存实验");

		gotonextstep(num, flag);
		return;
	}
	// console.log("修改实验");
	gotonextstep(num, flag);
}
//保存、修改作业
function SMcourseworkinfo(num, flag) {
	var divcan = $("#sethomework");
	if (!typeof (LessonID) == "number") {
		$("#sethomeworkIframe")[0].contentWindow.uploadExercises();
		// console.log("保存作业");

		gotonextstep(num, flag);
		return;
	}
	// console.log("修改作业");
	$("#sethomeworkIframe")[0].contentWindow.uploadExercises();
	gotonextstep(num, flag);
}
//发布课程
function coursepublish() {
	if (coursepublish.published) {
		return;
	}
	layui.use('laydate');
	var datepicker = '<input id="DatePicker" class="layui-input" style="width: 100%;" placeholder="' + langThis("cs_chooseDate") + '" onclick="layui.laydate({elem:this,min:laydate.now(0),max: laydate.now(+365),format:\'YYYY-MM-DD\',festival:true})">';
	var pub = function () {
		var enddate = $("#DatePicker").val().trim();
		if (!enddate) {
			return;
		}
		var loading = layer.load(2, {
			shade: [0.5, "#eee"]
		});
		$.ajax({
			url: "lessons/" + LessonID + "/publish",
			type: "POST",
			contentType: "application/json",
			data: JSON.stringify({ "enddate": enddate }),
			dataType: "json",
			success: function (data) {
				coursepublish.published = true;
				layer.close(loading);
				layer.msg(langThis("mi_OprationSucess"), { icon: 1 });
			},
			error: function (event) {
				coursepublish.published = false;
				layer.close(loading);
				layer.msg(langThis("role_optionfaild"), { icon: 2 });
			}
		});
	};
	layer.confirm(datepicker, {
		btn: [langThis("mc_publishcoursebtn"), langThis("pm_cancle")]
	}, pub);
	// 标题
	var header = $("div.layui-layer.layui-layer-dialog.layer-anim>div.layui-layer-title");
	header.html("<span class='glyphicon glyphicon-info-sign'></span>&nbsp;" + langThis("cs_setchooseEndDate"));
	header.css({
		'color': "#fff",
		'background-color': '#3071a9',
		'font-weight': 'bold'
	});
}
//子页面调用layer.msg
function childmsg(msg) {
	layer.msg(msg);
}
//子页面调用显隐实验底部按钮
function hideSavebtn(bl) {
	if (!bl) {
		$("#setcourseexcise>button.actBTN").show();
	} else {
		$("#setcourseexcise>button.actBTN").hide();
	}
}
//子页面确认弹窗
function pLayerConfirm(title, msg, btn1, btn2, fun1, fun2) {
	// title{text,{color,background-color}}
	layer.confirm(msg, {
		btn: [btn1, btn2]
	}, fun1, fun2);
	// 标题
	var header = $("div.layui-layer.layui-layer-dialog.layer-anim>div.layui-layer-title");
	if (typeof (title) == "string") {
		header.html(title);
		return;
	}
	header.html(title.text);
	header.css(title.css);
}